package cn.wolfcode.crm.web.controller;


import cn.wolfcode.crm.domain.AgencyInfo;
import cn.wolfcode.crm.query.AgencyInfoQueryObject;
import cn.wolfcode.crm.query.PageResult;
import cn.wolfcode.crm.service.IAgencyInfoService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * @author konki
 * @time   2018年6月19日 下午7:03:47
 * @email  konki@qq.com
 * @description 
 */
@Controller
@RequestMapping("agencyInfo")
public class AgencyInfoController {
	@Autowired
   private IAgencyInfoService agencyInfoService;

	@RequestMapping("")
	@PermissionName("机构列表")
	@RequiresPermissions("agencyInfo:index")
	public String index(){
		return "agencyInfo/list";
	}

    @RequestMapping("list")
	@ResponseBody
	@PermissionName("机构列表")
	@RequiresPermissions("agencyInfo:list")
	public PageResult list(AgencyInfoQueryObject qo){
        System.out.println(qo.getKeyword());
        return agencyInfoService.query(qo);
	}

	//保存
    @RequestMapping("save")
    @ResponseBody
    @PermissionName("机构保存")
    @RequiresPermissions("agencyInfo:save")
    public JsonResult save(AgencyInfo entity){
        JsonResult result = new JsonResult();
        try{
            agencyInfoService.insert(entity);
        }catch(Exception e){
            e.printStackTrace();
            result.markMsg("保存失败");
        }
        return  result;
    }
	//保存
    @RequestMapping("update")
    @ResponseBody
    @PermissionName("机构更新")
    @RequiresPermissions("agencyInfo:update")
    public JsonResult update(AgencyInfo entity){
        JsonResult result = new JsonResult();
        try{
            agencyInfoService.updateByPrimaryKey(entity);
        }catch(Exception e){
            e.printStackTrace();
            result.markMsg("更新失败");
        }
        return  result;
    }

    @RequestMapping("changeState")
    @ResponseBody
    @RequiresPermissions("agencyInfo:changeState")
    @PermissionName("机构状态")
    public JsonResult changeState(Long id){
        JsonResult result = new JsonResult();
        try {
            agencyInfoService.changeState(id);
        }catch (Exception e){
            e.printStackTrace();
            result.markMsg("操作失败");
        }
        return result;
    }

    //查出所有机构
    @RequestMapping("queryAllAgencyInfo")
    @ResponseBody
    public List<AgencyInfo> queryAllAgencyInfo(){
        return agencyInfoService.selectAll();
    }
    //查机构
    @RequestMapping("queryAgencys")
    @ResponseBody
    public List<AgencyInfo> queryAgencys(){
        return agencyInfoService.selectAll();
    }



}
